package com.supply.dl.view;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.supply.dl.R;

/**
 * 登出弹出框
 */
public class LoginOutDialog extends Dialog {
    private Context mContext;  //上下文
    private DisplayMetrics mDisplayMetrics;

    public LoginOutDialog(@NonNull Context context) {
        super(context);
        this.mContext = context;
        init();
    }

    private void init() {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        mDisplayMetrics = mContext.getResources().getDisplayMetrics();
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_login_out, null);
        setContentView(view);
    }

    @Override
    public void show() {
        super.show();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        getWindow().setLayout(getLayoutWidth() - 150, WindowManager.LayoutParams.WRAP_CONTENT);
    }

    public int getLayoutWidth() {
        float size = Math.max(mDisplayMetrics.widthPixels, mDisplayMetrics.widthPixels);
        return (int) (size);
    }
}
